/*********************************************************************
	Rhapsody	: 7.5.2
	Login		: dan
	Component	: Test
	Configuration 	: DefaultConfig
	Model Element	: TCSC_tc_0
//!	Generated Date	: Sat, 18, Dec 2010 
	File Path	: Test/DefaultConfig/TPkg_RobotController/TCSC_tc_0.java
*********************************************************************/

package TPkg_RobotController;

//## dependency RobotPkg 
import RobotPkg.*;
//## operation TCSC_tc_0( TCon_RobotController, RobotController) 
import RobotPkg.RobotController;
//## auto_generated
import com.ibm.rational.rhapsody.oxf.*;
//## auto_generated
import org.btc.TestConductor.TestConductor;
//## auto_generated
import com.ibm.rational.rhapsody.oxf.states.*;

//----------------------------------------------------------------------------
// TPkg_RobotController/TCSC_tc_0.java                                                                  
//----------------------------------------------------------------------------

//## package TPkg_RobotController 


//## class TCSC_tc_0 
public class TCSC_tc_0 implements RiJStateConcept {
    
    public Reactive reactive;		//## ignore 
    
    protected RobotController itsRobotController;		//## link itsRobotController 
    
    protected TCon_RobotController itsTCon;		//## link itsTCon 
    
    //#[ ignore 
    public static final int RiJNonState=0;
    public static final int terminationstate_0=1;
    public static final int state_4=2;
    public static final int state_3=3;
    public static final int state_1=4;
    public static final int initial=5;
    public static final int final_state=6;
    //#]
    protected int rootState_subState;		//## ignore 
    
    protected int rootState_active;		//## ignore 
    
    public static final int TCSC_tc_0_Timeout_state_4_id = 1;		//## ignore 
    
    public static final int TCSC_tc_0_Timeout_state_3_id = 2;		//## ignore 
    
    
    //## statechart_method 
    public RiJThread getThread() {
        return reactive.getThread();
    }
    
    //## statechart_method 
    public void schedTimeout(long delay, long tmID, RiJStateReactive reactive) {
        getThread().schedTimeout(delay, tmID, reactive);
    }
    
    //## statechart_method 
    public void unschedTimeout(long tmID, RiJStateReactive reactive) {
        getThread().unschedTimeout(tmID, reactive);
    }
    
    //## statechart_method 
    public boolean isIn(int state) {
        return reactive.isIn(state);
    }
    
    //## statechart_method 
    public boolean isCompleted(int state) {
        return reactive.isCompleted(state);
    }
    
    //## statechart_method 
    public RiJEventConsumer getEventConsumer() {
        return (RiJEventConsumer)reactive;
    }
    
    //## statechart_method 
    public void gen(RiJEvent event) {
        reactive._gen(event);
    }
    
    //## statechart_method 
    public void queueEvent(RiJEvent event) {
        reactive.queueEvent(event);
    }
    
    //## statechart_method 
    public int takeEvent(RiJEvent event) {
        return reactive.takeEvent(event);
    }
    
    // Constructors
    
    //## operation TCSC_tc_0( TCon_RobotController, RobotController) 
    public  TCSC_tc_0( TCon_RobotController tcon,  RobotController arg_RobotController, RiJThread p_thread) {
        reactive = new Reactive(p_thread);
        //#[ operation TCSC_tc_0( TCon_RobotController, RobotController) 
        itsTCon = tcon;
        itsRobotController = arg_RobotController;
        
        //#]
    }
    //## auto_generated 
    public  TCSC_tc_0(RiJThread p_thread) {
        reactive = new Reactive(p_thread);
    }
    
    //## auto_generated 
    public RobotController getItsRobotController() {
        return itsRobotController;
    }
    
    //## auto_generated 
    public void setItsRobotController(RobotController p_RobotController) {
        itsRobotController = p_RobotController;
    }
    
    //## auto_generated 
    public TCon_RobotController getItsTCon() {
        return itsTCon;
    }
    
    //## auto_generated 
    public void setItsTCon(TCon_RobotController p_TCon_RobotController) {
        itsTCon = p_TCon_RobotController;
    }
    
    //## auto_generated 
    public boolean startBehavior() {
        boolean done = false;
        done = reactive.startBehavior();
        return done;
    }
    
    //## ignore 
    public class Reactive extends RiJStateReactive {
        
        // Default constructor 
        public Reactive() {
            this(RiJMainThread.instance());
        }
        
        
        // Constructors
        
        public  Reactive(RiJThread p_thread) {
            super(p_thread);
            initStatechart();
        }
        
        //## statechart_method 
        public boolean isIn(int state) {
            if(rootState_subState == state)
                {
                    return true;
                }
            return false;
        }
        
        //## statechart_method 
        public boolean isCompleted(int state) {
            return true;
        }
        
        //## statechart_method 
        public void rootState_entDef() {
            {
                rootState_enter();
                rootStateEntDef();
            }
        }
        
        //## statechart_method 
        public int rootState_dispatchEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            switch (rootState_active) {
                case initial:
                {
                    res = initial_takeEvent(id);
                }
                break;
                case state_1:
                {
                    res = state_1_takeEvent(id);
                }
                break;
                case final_state:
                {
                    res = final_state_takeEvent(id);
                }
                break;
                case terminationstate_0:
                {
                    res = terminationstate_0_takeEvent(id);
                }
                break;
                case state_3:
                {
                    res = state_3_takeEvent(id);
                }
                break;
                case state_4:
                {
                    res = state_4_takeEvent(id);
                }
                break;
                default:
                    break;
            }
            return res;
        }
        
        //## auto_generated 
        protected void initStatechart() {
            rootState_subState = RiJNonState;
            rootState_active = RiJNonState;
        }
        
        //## statechart_method 
        public void state_3_entDef() {
            state_3_enter();
        }
        
        //## statechart_method 
        public void state_4_exit() {
            state_4Exit();
        }
        
        //## statechart_method 
        public void terminationstate_0Exit() {
        }
        
        //## statechart_method 
        public void terminationstate_0Enter() {
        }
        
        //## statechart_method 
        public void state_1Enter() {
        }
        
        //## statechart_method 
        public void state_3_exit() {
            state_3Exit();
        }
        
        //## statechart_method 
        public int final_state_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(RiJEvent.NULL_EVENT_ID))
                {
                    res = final_stateTakeNull();
                }
            
            return res;
        }
        
        //## statechart_method 
        public int state_1TakeNull() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            state_1_exit();
            //#[ transition 2 
            TestConductor.ASSERT_NAME("Sensor initial value", itsRobotController.getSensor(0).getLine() == false);
            
            itsRobotController.getSensor(0).gen(new lineSeen());
            //#]
            state_3_entDef();
            res = RiJStateReactive.TAKE_EVENT_COMPLETE;
            return res;
        }
        
        //## statechart_method 
        public int state_3_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(RiJEvent.TIMEOUT_EVENT_ID))
                {
                    res = state_3TakeRiJTimeout();
                }
            
            return res;
        }
        
        //## statechart_method 
        public void terminationstate_0_exit() {
            terminationstate_0Exit();
        }
        
        //## statechart_method 
        public void terminationstate_0_entDef() {
            terminationstate_0_enter();
        }
        
        //## statechart_method 
        public void state_1_exit() {
            popNullConfig();
            state_1Exit();
        }
        
        //## statechart_method 
        public void state_1_entDef() {
            state_1_enter();
        }
        
        //## statechart_method 
        public void terminationstate_0_enter() {
            rootState_subState = terminationstate_0;
            rootState_active = terminationstate_0;
            terminationstate_0Enter();
        }
        
        //## statechart_method 
        public void final_stateEnter() {
        }
        
        //## statechart_method 
        public int initial_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(RiJEvent.NULL_EVENT_ID))
                {
                    res = initialTakeNull();
                }
            
            return res;
        }
        
        //## statechart_method 
        public int state_3TakeRiJTimeout() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.getTimeoutId() == TCSC_tc_0_Timeout_state_3_id)
                {
                    state_3_exit();
                    //#[ transition 4 
                    TestConductor.ASSERT_NAME("Sensor state change", itsRobotController.getSensor(0).getLine() == true);
                    //#]
                    final_state_entDef();
                    res = RiJStateReactive.TAKE_EVENT_COMPLETE;
                }
            return res;
        }
        
        //## statechart_method 
        public void state_4_entDef() {
            state_4_enter();
        }
        
        //## statechart_method 
        public int rootState_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            return res;
        }
        
        //## statechart_method 
        public void final_state_entDef() {
            final_state_enter();
        }
        
        //## statechart_method 
        public void initial_enter() {
            pushNullConfig();
            rootState_subState = initial;
            rootState_active = initial;
            initialEnter();
        }
        
        //## statechart_method 
        public int terminationstate_0_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            return res;
        }
        
        //## statechart_method 
        public void final_state_exit() {
            popNullConfig();
            final_stateExit();
        }
        
        //## statechart_method 
        public void state_1Exit() {
        }
        
        //## statechart_method 
        public void rootState_enter() {
            rootStateEnter();
        }
        
        //## statechart_method 
        public void rootStateEnter() {
        }
        
        //## statechart_method 
        public void final_state_enter() {
            pushNullConfig();
            rootState_subState = final_state;
            rootState_active = final_state;
            final_stateEnter();
        }
        
        //## statechart_method 
        public void initialEnter() {
        }
        
        //## statechart_method 
        public void state_3Exit() {
            itsRiJThread.unschedTimeout(TCSC_tc_0_Timeout_state_3_id, this);
        }
        
        //## statechart_method 
        public void state_4Exit() {
            itsRiJThread.unschedTimeout(TCSC_tc_0_Timeout_state_4_id, this);
        }
        
        //## statechart_method 
        public void rootState_exit() {
            switch (rootState_subState) {
                case initial:
                {
                    initial_exit();
                }
                break;
                case state_1:
                {
                    state_1_exit();
                }
                break;
                case final_state:
                {
                    final_state_exit();
                }
                break;
                case terminationstate_0:
                {
                    terminationstate_0_exit();
                }
                break;
                case state_3:
                {
                    state_3_exit();
                }
                break;
                case state_4:
                {
                    state_4_exit();
                }
                break;
                default:
                    break;
            }
            rootState_subState = RiJNonState;
            rootStateExit();
        }
        
        //## statechart_method 
        public void rootStateEntDef() {
            initial_entDef();
        }
        
        //## statechart_method 
        public void initial_exit() {
            popNullConfig();
            initialExit();
        }
        
        //## statechart_method 
        public void state_1_enter() {
            pushNullConfig();
            rootState_subState = state_1;
            rootState_active = state_1;
            state_1Enter();
        }
        
        //## statechart_method 
        public void final_stateExit() {
        }
        
        //## statechart_method 
        public int state_1_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(RiJEvent.NULL_EVENT_ID))
                {
                    res = state_1TakeNull();
                }
            
            return res;
        }
        
        //## statechart_method 
        public void state_3_enter() {
            rootState_subState = state_3;
            rootState_active = state_3;
            state_3Enter();
        }
        
        //## statechart_method 
        public int state_4_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(RiJEvent.TIMEOUT_EVENT_ID))
                {
                    res = state_4TakeRiJTimeout();
                }
            
            return res;
        }
        
        //## statechart_method 
        public void state_4_enter() {
            rootState_subState = state_4;
            rootState_active = state_4;
            state_4Enter();
        }
        
        //## statechart_method 
        public void state_4Enter() {
            itsRiJThread.schedTimeout(1000, TCSC_tc_0_Timeout_state_4_id, this, null);
        }
        
        //## statechart_method 
        public void rootStateExit() {
        }
        
        //## statechart_method 
        public int initialTakeNull() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            initial_exit();
            //#[ transition 1 
            itsTCon.rtc_init();
            itsRobotController.gen(new evOnOff());
            //#]
            state_4_entDef();
            res = RiJStateReactive.TAKE_EVENT_COMPLETE;
            return res;
        }
        
        //## statechart_method 
        public void initialExit() {
        }
        
        //## statechart_method 
        public int state_4TakeRiJTimeout() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.getTimeoutId() == TCSC_tc_0_Timeout_state_4_id)
                {
                    state_4_exit();
                    //#[ transition 5 
                    TestConductor.ASSERT_NAME("Robot on",itsRobotController.isIn(Sensor.on));
                    //#]
                    state_1_entDef();
                    res = RiJStateReactive.TAKE_EVENT_COMPLETE;
                }
            return res;
        }
        
        //## statechart_method 
        public int final_stateTakeNull() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            final_state_exit();
            //#[ transition 3 
            itsRobotController.gen(new evOnOff());
            itsTCon.rtc_exit();
            //#]
            terminationstate_0_entDef();
            res = RiJStateReactive.TAKE_EVENT_COMPLETE;
            return res;
        }
        
        //## statechart_method 
        public void initial_entDef() {
            initial_enter();
        }
        
        //## statechart_method 
        public void state_3Enter() {
            itsRiJThread.schedTimeout(1000, TCSC_tc_0_Timeout_state_3_id, this, null);
        }
        
    }
}
/*********************************************************************
	File Path	: Test/DefaultConfig/TPkg_RobotController/TCSC_tc_0.java
*********************************************************************/

